package contorller;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/ABCServlet")
public class ABCServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;


    public ABCServlet() {
        System.out.println("执行构造方法");
    }

	public void init(ServletConfig config) throws ServletException {
		System.out.println("执行初始化方法");
	}

	public void destroy() {
		System.out.println("执行销毁方法");
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("My name is zhangsan, My server is Tomcat9.0, Served at: ").append(request.getContextPath());
		System.out.println("执行get方法");
		System.out.println("项目根目录是：" + request.getServletContext().getRealPath(""));
		
		System.out.println("使用 request 的 getParamter 获取参数");
		String name = request.getParameter("name");
		System.out.println("欢迎：" + name);
		
		String[] hobbies = request.getParameterValues("hobby");
		System.out.println("您的兴趣爱好是：");
		for (String hobby : hobbies) {
			System.out.println(hobby);
		}
		
		System.out.println("get方法执行完毕");
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
